/**
 * 
 */
package soa.security.mgr.service;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import soa.security.domain.Account;
import soa.security.domain.Applsystem;
import soa.security.exception.AuthenticationException;
import soa.security.exception.OrganizationException;
import soa.security.mgr.service.base.BaseMgrService;
import soa.security.ws.base.ModelAdapter;

import java.io.File;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * @author CreGu
 *
 */
public interface AccountMgrService extends BaseMgrService,
		ModelAdapter<Account> {
	
	public Page<Account> allAccounts(String organizationId,
			Map<String, Object> parameters, boolean subTree, PageRequest request) throws OrganizationException;
	
	List<Applsystem> allApplsystems(String organizationId, String accountId)
			throws OrganizationException;
	
	List<Applsystem> allApplsystems(Account account)
			throws OrganizationException;

	void addAccount(String organizationId, Account a)
			throws OrganizationException;

	List<Account> allAccounts(String organizationId)
			throws OrganizationException;

	List<Account> allAccounts(String organizationId,
			Map<String, Object> parameters, boolean subTree)
			throws OrganizationException;

	void updateAccount(String organizationId, Account a)
			throws OrganizationException;
	
	void updateLoginAccount(String organizationId, Account a)
			throws OrganizationException;

	void pwdReset(String organizationId, String accountId)
			throws OrganizationException;

	void pwdUpdate(String organizationId, String accountId, String password)
			throws OrganizationException;

	void disable(String organizationId, String accountId)
			throws OrganizationException;

	void pwdReset(String accountDn) throws OrganizationException;

	void disable(String accountDn) throws OrganizationException;

	void enable(String organizationId, String accountId)
			throws OrganizationException;

	void enable(String accountDn) throws OrganizationException;

	Account authenticate(String uid, String password)
			throws OrganizationException;

	Account systemLogin(String bid, String orginationDN, String password)
			throws AuthenticationException;

	Account findByUid(String uid) throws OrganizationException;

	Account findByDn(String dn) throws OrganizationException;

	boolean deleteByDn(String dn) throws OrganizationException;

	boolean importAccounts(String organizationId, InputStream is)
			throws OrganizationException;

	boolean importAccounts(String organizationId, boolean globaled,
			InputStream is) throws OrganizationException;

	List<Account> findByPersonUid(String organizationId, String personUid)
			throws OrganizationException;

	List<Account> findNonByPersonUid(String organizationId, String personUid)
			throws OrganizationException;

	void updateAccount(String organizationId, String accountDns,
			String personUid);

	/**
	 * 提供的密码是否与，dn所对应的Account的密码一致
	 * 
	 * @param uid
	 * @param password
	 *            密码原文
	 * @return boolean
	 * 
	 * @author Cre.Gu at 2015年5月21日
	 */
	boolean compareCredentials(String uid, String password);

	// /**
	// * 使用Apache DS 的unlock方式，通过将属性pwdAccountLockedTime删除，达到unlock
	// *
	// * @param accountDn
	// * void
	// *
	// * @author Cre.Gu at 2015年5月21日
	// */
	// void unlockByLdap(String accountDn);

	List<Account> findByBase(String baseDn);

	void initializeSuperAccount();

	Account existAccount(String organizationId, Account a);

	public File getTemplate();

	public File getError();

	void bind(String organizationId, String accountId, String personId);
	
	boolean addApplsystem(String organizationId, String accountId, String applsystemId) throws OrganizationException;
}
